﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Logging;

namespace MMITIntegration
{
    public class UkashIntegration
    {
        IntegrationResponse ir = new IntegrationResponse();
        //Live
        UkashService.UkashService Service = new UkashService.UkashService();

        //Staging
        //UkashStagingService.UkashService Service = new UkashStagingService.UkashService();

        //SynkronLogger Log = new SynkronLogger("MMITIntegration");
        SynkronLogger Log = new SynkronLogger("MMITCore");
        
        Dictionary<string, object> d = new Dictionary<string, object>();
        
       public IntegrationResponse RedeemUkash (decimal Amount, string VoucherNumber, string Currency, decimal  PurchaseValue)
        {
            // Staging
            //UkashInput ui = new UkashInput { UkashAmountReference = "", UkashBaseCurrency = Currency, UkashBrandID = "UKASH10082", UkashLogin = "UKASHTESTMERCHANT", UkashMerchantCustomerValue = "", UkashMerchantDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), UkashPassword = "password123", UkashRedemptionType = "3", UkashStoreLocationId = "",  UkashTransactionID = "UKASH" + RandomStringHelper.GenerateStringWithDigits(10), UkashVoucherNumber = VoucherNumber, UkashVoucherValue = Amount.ToString("0.00") };
            //Live
            UkashInput ui = new UkashInput { UkashAmountReference = "", UkashBaseCurrency = Currency, UkashBrandID = "UKASH17735", UkashLogin = "UKASH_MobileMedia", UkashMerchantCustomerValue = "", UkashMerchantDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), UkashPassword = "MQxwkG8n9doE4qOj", UkashRedemptionType = "3", UkashStoreLocationId = "", UkashTransactionID = "UKASH" + RandomStringHelper.GenerateStringWithDigits(10), UkashVoucherNumber = VoucherNumber, UkashVoucherValue = Amount.ToString("0.00") };
           if (PurchaseValue > 0 )
            {
                ui.UkashTicketValue = Convert.ToDecimal(PurchaseValue).ToString("0.00");
            }
            else
            {
                ui.UkashTicketValue = "";
            }
           //UkashOutput uo =  UkashOutput.FromString(Service.Redemption(ui.ToString()));

           UkashOutput uo =  UkashOutput.FromString(Service.Redemption(ui.ToString()));
            d.Add(ui.UkashTransactionID, Log.Desc(uo));

            Log.WriteInformation(675643222, "UkashResponse", d);
            ir.errDescription = uo.ErrDescription;
            ir.txtDescription = uo.TxDescription;
            ir.TransactionCode = uo.TxCode;
            ir.IntegrationParty = IntegrationParty.Ukash;
            ir.IntegrationTransactionCode = uo.TransactionId;
            ir.UO = uo;
            return ir;
        }
    }
}